/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Main Information      ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

var

	RDDeck = list()

client/var

	RDcard1 = ""
	RDcard1suit = ""

	RDcard2 = ""
	RDcard2suit = ""

	RDcard3 = ""
	RDcard3suit = ""

	selectedChip = 0

	RDBet = 0
	RDBonus = 0

	RDBetLimit = 30000
	RDBonusLimit = 6000

	Raise = FALSE
	Spread = 0

	RDStatus = FALSE

	RDBetWin = 0
	RDBonusWin = 0

	RDBonusLight = 0

	RDWinnings = 0




/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Main Information      ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

client/verb

	RD10()
		set hidden = 1
		selectedChip = 10
		RDUpdateVisuals()

	RD50()
		set hidden = 1
		selectedChip = 50
		RDUpdateVisuals()

	RD100()
		set hidden = 1
		selectedChip = 100
		RDUpdateVisuals()

	RD500()
		set hidden = 1
		selectedChip = 500
		RDUpdateVisuals()

	RD2500()
		set hidden = 1
		selectedChip = 2500
		RDUpdateVisuals()

	RDBet()
		set hidden = 1
		if(selectedChip != 0 && !RDStatus)

			RDBet += selectedChip

			if(RDBet + RDBonus > RDBetLimit)
				RDBet = RDBetLimit - RDBonus

			RDUpdateVisuals()


	RDBonus()
		set hidden = 1
		if(selectedChip != 0 && !RDStatus)

			RDBonus += selectedChip

			if(RDBonus + RDBet > RDBetLimit)
				RDBonus = RDBetLimit - RDBet
				if(RDBonus > RDBonusLimit)
					RDBonus = RDBonusLimit

			RDUpdateVisuals()

	RDClearBet()
		set hidden = 1
		if(!RDStatus) RDBet = 0
		RDUpdateVisuals()

	RDClearBonus()
		set hidden = 1
		if(!RDStatus) RDBonus = 0
		RDUpdateVisuals()

	RDCall()
		set hidden = 1
		if(RDStatus) RDCallBet()

	RDRaise()
		set hidden = 1
		if(RDStatus) RDRaiseBet()

	RDDeal()
		set hidden = 1
		if(!RDStatus)
			RDShuffle()
			RDDealCards()


/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Main Information      ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

client/proc

	RDClose()
		for(var/i=14; i!=0; i--) RDUnlightSpread(i)

	RDInit()
		winset(src,"Games_RedDog.card1","image=\"[BACK]\"")
		winset(src,"Games_RedDog.card2","image=\"[BACK]\"")
		winset(src,"Games_RedDog.card3","image=\"[BACK]\"")
		selectedChip = 0
		RDBet = 0
		RDBonus = 0
		RDStatus = FALSE
		RDFlipButtons()
		RDUpdateVisuals()

	RDShuffle()
		RDDeck = list()
		for(var/i = 2; i <= 365; i++)
			RDDeck+=i

	RDClear()
		Raise = FALSE
		RDBonusWin = 0
		RDBetWin = 0
		RDWinnings = 0
		winset(src,"Games_RedDog.card1","image=\"[BACK]\"")
		winset(src,"Games_RedDog.card2","image=\"[BACK]\"")
		winset(src,"Games_RedDog.card3","image=\"[BACK]\"")
		winset(src,"Games_RedDog.betlabel","text=[RDBetWin]")
		winset(src,"Games_RedDog.bonuslabel","text=[RDBonusWin]")
		RDUpdateVisuals()


	RDFlipButtons()
		if(RDStatus)
			winset(src,"Games_RedDog.Deal","is-visible=false")
			winset(src,"Games_RedDog.Raise","is-visible=true")
			winset(src,"Games_RedDog.Call","is-visible=true")
		else
			winset(src,"Games_RedDog.Deal","is-visible=true")
			winset(src,"Games_RedDog.Raise","is-visible=false")
			winset(src,"Games_RedDog.Call","is-visible=false")

	RDUpdateVisuals()
		if(Raise) winset(src,"Games_RedDog.Bet","text=[RDBonus*2]")
		else winset(src,"Games_RedDog.Bonus","text=[RDBonus]")
		winset(src,"Games_RedDog.Bet","text=[RDBet]")
		winset(src,"Games_RedDog.Selected","text=[selectedChip]")
		winset(src,"Games_RedDog.betlabel","text=[RDBetWin]")
		winset(src,"Games_RedDog.bonuslabel","text=[RDBonusWin]")

	RDreturnCard(var/cardnum as num)
		while(cardnum > 53)
			cardnum = cardnum-52
		return cardnum

	RDreturnCardNumber(var/cardnum as num)
		while(cardnum > 14)
			cardnum = cardnum-13
		return cardnum

	RDcardVisual(var/cardnum as num)
		if(cardnum == 14) return "A"
		else if(cardnum == 11) return "J"
		else if(cardnum == 12) return "Q"
		else if(cardnum == 13) return "K"
		else return cardnum

	RDreturnCardSuit(var/cardnum as num)
		if(cardnum < 15) return "Spades"
		else if(cardnum < 28) return "Clubs"
		else if(cardnum < 41) return "Hearts"
		else return "Diamonds"

	RDLightSpread(var/number as num)
		winset(src,"Games_RedDog.S[number]s","is-visible=true")

	RDUnlightSpread(var/number as num)
		winset(src,"Games_RedDog.S[number]s","is-visible=false")

	RDLightBonus(var/number as num)
		winset(src,"Games_RedDog.B[number]","is-visible=true")

	RDUnlightBonus(var/number as num)
		winset(src,"Games_RedDog.B[number]","is-visible=false")

	RDDealCards()
		if(Spread)
			RDUnlightSpread(Spread)
			Spread = 0
		if(RDBonusLight)
			RDUnlightBonus(RDBonusLight)
			RDBonusLight = 0

		//

		RDClear()

		//

		LoadCasino()
		if(Credits < RDBet + RDBonus || RDBet + RDBonus == 0) return
		RDStatus = TRUE
		Credits -= RDBet + RDBonus
		SaveCasino()
		UpdateCredits()

		////
		// Shuffle and pick out the cards
		////

		/*
		RDShuffle()
		var/card1 = pick(RDDeck); RDDeck-=card1
		var/card2 = pick(RDDeck); RDDeck-=card2
		var/card3 = pick(RDDeck); RDDeck-=card3
		card1 = RDreturnCard(card1)
		card2 = RDreturnCard(card2)
		card3 = RDreturnCard(card3)
		RDcard1 = RDreturnCardNumber(card1)
		RDcard1suit = RDreturnCardSuit(card1)
		RDcard2 = RDreturnCardNumber(card2)
		RDcard2suit = RDreturnCardSuit(card2)
		*/

		RDcard1 = rand(2,14)
		RDcard1suit = pick("Hearts","Spades","Diamonds","Clubs")
		RDcard2 = rand(2,14)
		RDcard2suit = pick("Hearts","Spades","Diamonds","Clubs")

		if(RDcard1 > RDcard2)
			var/temp = RDcard2
			RDcard2 = RDcard1
			RDcard1 = temp

		//RDcard3 = RDreturnCardNumber(card3)
		//RDcard3suit = RDreturnCardSuit(card3)

		RDcard3 = rand(2,14)
		RDcard3suit = pick("Hearts","Spades","Diamonds","Clubs")

		////
		// Show the cards
		////

		sleep(5)
		winset(src,"Games_RedDog.card1","image=\"[CardImage(RDcard1, RDcard1suit)]\"")
		sleep(5)
		winset(src,"Games_RedDog.card2","image=\"[CardImage(RDcard2, RDcard2suit)]\"")

		////
		// Show the spread
		////

		Spread = RDcard2 - RDcard1
		if(Spread == 1) Spread = 12
		else if(Spread == 0) Spread = 13
		else Spread = Spread-1
		RDLightSpread(Spread)

		////
		// BONUS
		////

		if(RDcardVisual(RDcard2) == "A")
			if(RDcardVisual(RDcard1) == "A")
				RDBonusWin = 31

			else if(RDcardVisual(RDcard1) == "K")
				if(RDcard1suit == RDcard2suit) RDBonusWin = 26
				else RDBonusWin = 16

			else if(RDcardVisual(RDcard1) in list("Q","J"))
				if(RDcard1suit == RDcard2suit) RDBonusWin = 21
				else RDBonusWin = 6

		else if(RDcard1 == RDcard2)
			if(RDcard1 <= 10) RDBonusWin = 4
			else RDBonusWin = 11

		if(RDBonusWin != 0)
			RDBonusLight = RDBonusWin-1
			RDBonusWin = RDBonusWin * RDBonus
			RDLightBonus(RDBonusLight)
			RDUpdateVisuals()

		if(Spread == 12 || Spread == 13) RDCallBet()
		else RDFlipButtons()

		SaveCasino()

	RDDraw()
		////
		// Show third card
		////

		if(Spread != 12) winset(src,"Games_RedDog.card3","image=\"[CardImage(RDcard3, RDcard3suit)]\"")

		////
		// HAND
		////

		if(Spread == 13 && RDcard1 == RDcard2 && RDcard2 == RDcard3)
			// Triple
			RDUnlightSpread(13)
			RDLightSpread(14)
			Spread=14
			RDBetWin = 11

		else if(Spread == 13 || Spread == 12) RDBetWin = 1
		else if(Spread == 1 && RDcard3 > RDcard1 && RDcard3 < RDcard2) RDBetWin = 6
		else if(Spread == 2 && RDcard3 > RDcard1 && RDcard3 < RDcard2) RDBetWin = 5
		else if(Spread == 3 && RDcard3 > RDcard1 && RDcard3 < RDcard2) RDBetWin = 3
		else if(RDcard3 > RDcard1 && RDcard3 < RDcard2) RDBetWin = 2

		if(RDBetWin != 0)
			RDBetWin = RDBetWin * RDBet
			if(Raise) RDBetWin *= 2

		RDWinnings = RDBetWin + RDBonusWin

		Raise = FALSE

		Credits += RDWinnings
		RDStatus = FALSE
		RDFlipButtons()
		SaveCasino()
		UpdateCredits()
		RDUpdateVisuals()

	RDRaiseBet()
		if(Credits < RDBet) return
		Raise = TRUE
		Credits-=RDBet

		RDFlipButtons()
		RDUpdateVisuals()
		UpdateCredits()

		RDDraw()

	RDCallBet()
		RDFlipButtons()
		RDUpdateVisuals()
		RDDraw()

